function bindEvent() {
    $(".menu-title").click(function () {
        var a = $(this), b = a.next(), c = a.data("index");
        b.slideToggle("fast", resolveMenu(c))
    })
}

function resolveSwitch(a, b) {
    var c = {};
    "change" == b ? "on" == a ? (c = props.converter["off"], $(".menu-container").css({width: "30px"}), $(".content-container").css({left: "30px"}), $(".menu-container .list-group").hide()) : (c = props.converter["on"], $(".menu-container").css({width: "180px"}), $(".content-container").css({left: "180px"}), $(".menu-container .list-group").show()) : c = props.converter[a], data.converter = c
}

function resolveMenu(a) {
    var e, f, g, b = data.menus, c = b[a], d = c.iconStatus;
    if ("close" == d) {
        for (e in b) f = b[e], g = f.iconStatus, "open" == g && ($(".menu" + e).next().slideUp("fast"), f.iconStatus = "close", f.iconClass = props.menu.close.clz);
        c.iconStatus = "open", c.iconClass = props.menu.open.clz
    } else c.iconStatus = "close", c.iconClass = props.menu.close.clz
}

function request() {
    var a = util.load();
    util.syncPost({
        url: "user/detail", success: function (a) {
            loadSuccess = !0, data.user = a, processMenus()
        }, fail: function (a, b) {
            loadSuccess = !1, util.alert(b)
        }, complete: function () {
            layer.close(a)
        }
    })
}

function processMenus() {
    var b, c, d, e, f, a = data.user.menu.menus;
    for (b in a) {
        c = a[b], d = c.subMenus, c.iconStatus = props.menu.close.status, c.iconClass = props.menu.close.clz;
        for (b in d) e = d[b], f = e.url, "" == $.trim(f) && (e.url = "javascript:promptNo();")
    }
    data.menus = a
}

function modifyPwd() {
    var e, f, a = $(".pwd-div"), b = a.find(".oldPwd"), c = a.find(".newPwd"), d = a.find(".confirmPwd");
    return "" == $.trim(form.oldPassword) ? (data.message = "请填写原密码！", b.focus(), void 0) : "" == $.trim(form.newPassword) ? (data.message = "请填写新密码！", c.focus(), void 0) : form.newPassword.length < 6 ? (data.message = "新密码长度应大于6位！", c.focus(), void 0) : form.confirmPassword != form.newPassword ? (data.message = "两次密码输入不一致！", d.focus(), void 0) : (e = $(".pwd-div .modify-pwd-btn"), f = e.html(), e.html("修改中..."), e.attr("disabled", "true"), util.syncPost({
        url: "user/modifyPassword",
        data: form,
        success: function () {
            data.message = "", layer.close(boxId), util.alert("操作成功")
        },
        fail: function (a, b) {
            data.message = b
        },
        complete: function () {
            e.html(f), e.removeAttr("disabled")
        }
    }), void 0)
}

function promptNo() {
    util.alert("暂未开通！")
}

var boxId, loadSuccess = !1, vue = {}, data = {}, form = {}, props = {
    converter: {
        on: {status: "on", clz: "glyphicon glyphicon-option-horizontal"},
        off: {status: "off", clz: "glyphicon glyphicon-option-vertical"}
    },
    menu: {
        close: {status: "close", clz: "glyphicon glyphicon-chevron-right"},
        open: {status: "open", clz: "glyphicon glyphicon-chevron-down"}
    }
};
vue.initialize = function () {
    request(), resolveSwitch("on"), form.oldPassword = "", form.newPassword = "", form.confirmPassword = "", data.message = "", data.form = form, new Vue({
        el: ".wrap",
        data: data,
        methods: vue
    }), Vue.nextTick(function () {
        loadSuccess && (bindEvent(), $(".wrap").show(), $(".menu-title")[0].click())
    })
}, vue.change = function () {
    resolveSwitch(data.converter.status, "change")
}, vue.logout = function () {
    layer.confirm("确定注销？", {title: "提示", icon: 3}, function (a) {
        layer.close(a);
        var b = util.load();
        util.post({
            url: "user/logout", success: function () {
                window.top.location.href = "login"
            }, complete: function () {
                layer.close(b)
            }
        })
    })
}, vue.popModifyBox = function () {
    var a = $(".pwd-div");
    form.oldPassword = "", form.newPassword = "", form.confirmPassword = "", data.message = "", boxId = layer.open({
        type: 1,
        shift: 2,
        area: ["320px", "300px"],
        title: "修改密码",
        content: a
    })
}, vue.modifyPwd = function () {
    modifyPwd()
}, vue.closeModifyBox = function () {
    layer.close(boxId)
};